import type { codeRes, codeType, getPatirntInfo, getPatirntType, PatientType, userType } from '@/types/user'
import { request } from '@/utils/request'

/**
 * 登录页面
 * @params data
 */

export const loginByAPI = (mobile: string, password: string) =>
  request<userType>('/login/password', 'POST', { password, mobile })

/**
 * 注册页面
 * @param mobile 手机号
 * @param code 验证码
 * @param password 密码
 * @returns promise对象
 */
export const registerByAPI = (mobile: string, code: string, password: string) =>
  request<userType>('/register', 'POST', { mobile, code, password })


/**
 * 获取手机验证码
 * @param mobile 手机号
 * @param type 区分验证码的类型
 * @returns Promise对象
 */
export const sendMSMCAPI = (mobile: string, type: codeType) => 
  request<codeRes>('/code','GET', { mobile, type })

/**
 * 登录--手机验证码登录
 * @param mobile 手机号
 * @param code 验证码
 * @returns Promise对象
 */
export const loginByCodeAPI = (mobile: string, code: string) =>
  request<userType>('/login', 'POST', {mobile,code})


/**
 * 我的-获取个人用户信息
 * @returns Promise对象
 */
export const getUserInfoAPI = () => 
  request<PatientType>('/patient/myUser', 'GET')

/**
 * 获取患者列表
 * @returns Promise对象
 */
export const getPatientListAPI = () => 
  request<getPatirntInfo>('/patient/mylist')


/**
 * 问诊-添加患者信息
 * @param patient 
 * @returns Promise对象
 */
export const addPatientAPI = (patient: getPatirntType) => 
  request('/patient/add', 'POST', patient)


/**
 * 问诊-编辑患者信息
 * @param patient 
 * @returns Promise对象 
 */
export const updataPatientAPI = (patient: getPatirntType) => 
  request('/patient/update', 'PUT', patient)

/**
 * 问诊-删除患者信息
 * @param id 
 * @returns 
 */
export const delPatientAPI = (id: string) => 
  request(`/patient/del/${id}`, 'DELETE' )

/**
 * 登录--三方登录--qq三方登录
 * @param openId 
 * @returns 
 */
export const loginByQQAPI = (openId: string) => 
  request<userType>('/login/thirdparty', 'POST', { openId, source: 'qq' } )

/**
 * 登录--绑定用户新-三方登录绑定手机号
 * @param data 
 * @returns 
 */
export const bindMobileAPI = (data: {
  mobile: string,
  code: string,
  openId: string
}) => 
  request<userType>('/login/binding', 'POST', data)